// const arr = [1, [2, [3, 4]], 5, 6, [3, 4, 5, [6]]]
let arr = [1, 2, 3, 4, 4]

// 层序遍历
function maxDepth(arr) {
  const queue = arr;
  let level = 0;
  while (queue.length) {
    let len = queue.length;
    while (len--) {
      let temp = queue.shift();
      if (Array.isArray(temp)) {
        queue.push(...temp);
      }
    }
    level++;
  }
  return level;
}

// 深度遍历
function maxDepth(arr) {
  let max = 0, level = 1;
  function dfs(arr) {
    for (const item of arr) {
      if (Array.isArray(item)) {
        level++
        dfs(item);
        level = 1;
      }
      if (level > max) {
        max = level;
      }
    }
  }
  dfs(arr);
  return max;
}

console.log(arr);
console.log(maxDepth(arr));
